package com.gj.factoryclass.controller;

import com.gj.factoryclass.mapper.FactoryClassMapper;
import com.gj.factoryclass.model.*;
import com.gj.factoryclass.service.FactoryClassService;
import com.gj.utli.ResultBuilderVo;
import com.gj.utli.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import java.util.List;

/**
 * Created by Tangyunhen on 2021-06-27.
 */
@RestController
@CrossOrigin
public class FactoryClassController {

    @Autowired
    private FactoryClassService factoryClassService;

    @PostMapping("/legalPlant/query")
    public ResultVo queryPage(@RequestBody FactoryClassServiceVo factoryClassServiceVo) {
        return factoryClassService.queryPage(factoryClassServiceVo);
    }

    @Autowired
    private FactoryClassMapper factoryClassMapper;
    @GetMapping("/legalPerson/ofCurrentUser")
    public ResultVo xiala(){
        Integer pid=1;
        Integer pid=2;
        Integer pid=5;
        List<LegalPersonVo> legalPersonVoList = factoryClassMapper.queryLegalPersonById(pid);
        return ResultBuilderVo.success(legalPersonVoList);
    }

     @PostMapping("/legalPlant/add")
    public ResultVo add(@RequestBody @Valid FactoryClassAddVo factoryClassAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return factoryClassService.add(factoryClassAddVo);

    }
    @PostMapping("/legalPlant/update")
    public ResultVo add(@RequestBody @Valid FactoryClassUpdateVo factoryClassUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return factoryClassService.update(factoryClassUpdateVo);
    }

    @PostMapping("legalPlant/updatestatus")
    public ResultVo updateStatus(@RequestBody FactoryClassUpdateStatusVo factoryClassUpdateStatusVo){
        return factoryClassService.updateStatus(factoryClassUpdateStatusVo);
    }






}